<?php
namespace app\api\controller;



class UserAddress extends Base
{
    // 不需要验证
    protected $excludeValidateCheck = [

    ];

    // 定义自动实例化模型
    protected $ModelPath = 'UserAddress';

    public function store()
    {
        //获取全部数据
        $data = request()->param();
        //获取用户ID
        $user_id = (int)request()->UserModel->id;
        //整理信息
        $data = [
            'user_id' => $user_id,
            'consignee' => $data['consignee'],
            'phone' => $data['phone'],
            'province_name' => $data['province_name'],
            'city_name' => $data['city_name'],
            'area_name' => $data['area_name'],
            'address' => $data['address'],
            'is_default' => 0,
            'latitude' => '',
            'longitude' => '',
            'province_id' => (int)$data['province_id'],
            'area_id' => (int)$data['area_id'],
            'city_id' => (int)$data['city_id'],
            'update_time' => date('Y-m-d H:i:s'),
        ];
        //判断是否为保存
        if (!$id = (int)request()->param('id', 0)) {
            //新增地址
            $id = $this->M->insertGetId($data);
        } else {
            //更新地址
            $this->M->where('id', $id)->update($data);
        }
        //返回地址ID
        return showSuccess(compact('id'));
    }
}